/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.util.ArrayList;

import javax.swing.JOptionPane;

import database.PersonDB;
import models.Person;

/**
 *
 * @author James
 */
public class Applicant4 extends javax.swing.JFrame {

    /**
     * Creates new form Applicant
     */
    
    Applicant a;
    Applicant2 a2;
    Applicant3 a3;
    
    public Applicant4() {
        initComponents();
    }
    
    public Applicant4(Applicant a, Applicant2 a2, Applicant3 a3) {
        initComponents();
        this.a=a;
        this.a2=a2;
        this.a3=a3;
    }
    
    

    public javax.swing.JTextArea getjTextArea1() {
		return jTextArea1;
	}

	public void setjTextArea1(javax.swing.JTextArea jTextArea1) {
		this.jTextArea1 = jTextArea1;
	}

	public javax.swing.JTextField getjTextField1() {
		return jTextField1;
	}

	public void setjTextField1(javax.swing.JTextField jTextField1) {
		this.jTextField1 = jTextField1;
	}

	/**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel15 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        
        jButton3.setVisible(false);

        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setTitle("New profile");
        setBounds(new java.awt.Rectangle(490, 170, 0, 0));
        
        jPanel1.setBackground(new java.awt.Color(204, 204, 255));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("New Applicant");

        jButton1.setText("Save");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("<< Back");

        jLabel14.setText("Courses done:");

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jLabel15.setText("Years of experience:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(149, 149, 149)
                                .addComponent(jLabel1))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel14))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 101, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jButton3)
                                .addGap(4, 4, 4)
                                .addComponent(jButton1))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(9, 9, 9)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    	if (this.jTextArea1.getText().isEmpty() || this.jTextField1.getText().isEmpty())
    		JOptionPane.showMessageDialog(this, "Please fill all the data.");
    	else{
	    	Person P = new Person();
	        P.setId(PersonDB.obtenerUltimoId());
	        P.setFirstName(a.getjTextField1().getText().toUpperCase());
	        P.setLastname(a.getjTextField2().getText().toUpperCase());
	        P.setAge(Integer.parseInt(a.getjTextField3().getText()));
	        P.setGender(a.getjComboBox1().getSelectedItem().toString().toUpperCase());
	        P.setCity(a.getjTextField4().getText().toUpperCase());
	        P.setInformationContact(a.getjTextArea1().getText());
	        ArrayList<String> Knowledges = new ArrayList<String>();
	        ArrayList<Integer> KnowledgesWeights = new ArrayList<Integer>();
	        ArrayList<String> Qualities = new ArrayList<String>();
	        ArrayList<Integer> QualitiesWeights = new ArrayList<Integer>();
	        ArrayList<String> studies = new ArrayList<String>();
	        for (int i=0;i<a2.getCantidad();i++){
	    		Knowledges.add(a2.getTextos().get(i).getText().toUpperCase());
	    		KnowledgesWeights.add(a2.getSliders().get(i).getValue());
	        }
	        Qualities.add(a3.getjLabel2().getText());
	        QualitiesWeights.add(a3.getjSlider1().getValue());
	        Qualities.add(a3.getjLabel3().getText());
	        QualitiesWeights.add(a3.getjSlider2().getValue());
	        Qualities.add(a3.getjLabel4().getText());
	        QualitiesWeights.add(a3.getjSlider3().getValue());
	        Qualities.add(a3.getjLabel5().getText());
	        QualitiesWeights.add(a3.getjSlider4().getValue());
	        Qualities.add(a3.getjLabel6().getText());
	        QualitiesWeights.add(a3.getjSlider5().getValue());
	        Qualities.add(a3.getjLabel7().getText());
	        QualitiesWeights.add(a3.getjSlider6().getValue());
	        Qualities.add(a3.getjLabel9().getText());
	        QualitiesWeights.add(a3.getjSlider7().getValue());
	        Qualities.add(a3.getjLabel10().getText());
	        QualitiesWeights.add(a3.getjSlider8().getValue());
	        Qualities.add(a3.getjLabel11().getText());
	        QualitiesWeights.add(a3.getjSlider9().getValue());
	        Qualities.add(a3.getjLabel12().getText());
	        QualitiesWeights.add(a3.getjSlider10().getValue());
	        Qualities.add(a3.getjLabel13().getText());
	        QualitiesWeights.add(a3.getjSlider11().getValue());
	    	String s[] = this.getjTextArea1().getText().split("\\s+");
	    	for (int i=0;i<s.length;i++){
	    		studies.add(s[i].toUpperCase());
	    	}
	    	P.setYears(Integer.parseInt(this.getjTextField1().getText()));
	    	P.setKnowledges(Knowledges);
	    	P.setKnowledgesWeights(KnowledgesWeights);
	    	P.setQualities(Qualities);
	    	P.setQualitiesWeights(QualitiesWeights);
	    	P.setStudies(studies);
	    	P.guardarEnBase();
	    	JOptionPane.showMessageDialog(this, "Applicant saved succesfully!");
	    	this.setVisible(false);
    	}
    }                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Applicant4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Applicant4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Applicant4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Applicant4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Applicant4().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                   
}
